package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.ProductService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/product/manage")
@CrossOrigin
@Api(value = "产品管理", description = "产品管理")
public class ProductController {

    private final ProductService productService;

    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增产品接口",notes = "新增产品接口")
    public LogicResponse save(@RequestBody @Validated ProductCreateDTO productCreateDTO) {
        productService.save(productCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改产品接口",notes = "修改产品接口")
    public LogicResponse update(@RequestBody @Validated ProductUpdateDTO productUpdateDTO) {
        productService.update(productUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除产品接口",notes = "删除产品接口")
    public LogicResponse delete(@RequestBody @Validated ProductIdDTO productIdDTO) {
        productService.delete(productIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询产品列表接口",notes = "查询产品列表接口")
    public LogicResponse queryProductPage(@RequestBody @Validated ProductQueryDTO productQueryDTO) {
        return LogicResponse.success(productService.getProductList(productQueryDTO));
    }

    @PostMapping("/cancel")
    @ApiOperation(value = "产品撤回接口",notes = "产品撤回接口")
    public LogicResponse cancel(@RequestBody @Validated ProductIdDTO ProductIdDTO) {
        productService.cancelProduct(ProductIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/preview")
    @ApiOperation(value = "预览产品接口/前端物料接口",notes = "预览产品接口/小程序端物料接口")
    public LogicResponse preview(@RequestBody @Validated ProductPreviewQueryDTO productPreviewDTO) {
        return LogicResponse.success(productService.previewProduct(productPreviewDTO));
    }

    @PostMapping("/submit")
    @ApiOperation(value = "产品提交审核接口",notes = "产品提交审核接口")
    public LogicResponse submit(@RequestBody @Validated ProductIdDTO productIdDTO) {
        productService.submitProduct(productIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/agree")
    @ApiOperation(value = "同意发布产品接口",notes = "同意发布产品接口")
    public LogicResponse agree(@RequestBody @Validated ProductIdDTO productIdDTO) {
        productService.agreeIssueProduct(productIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/agree/no")
    @ApiOperation(value = "不同意发布产品接口",notes = "不同意发产品接口")
    public LogicResponse agreeNo(@RequestBody @Validated ProductIdDTO productIdDTO) {
        productService.agreeNoIssueProduct(productIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/release")
    @ApiOperation(value = "发布产品接口",notes = "发产品接口")
    public LogicResponse release(@RequestBody @Validated ProductIdDTO productIdDTO) {
        productService.releaseProduct(productIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/sort")
    @ApiOperation(value = "产品顺序调整接口",notes = "产品顺序调整接口")
    public LogicResponse sort(@RequestBody @Validated ProductSortDTO productSortDTO) {
        productService.updateProductSort(productSortDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个产品详情")
    public LogicResponse getProductDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(productService.getProductDetail(baseIdDTO));
    }

    @PostMapping("/add/readCount")
    @ApiOperation(value = "点击一次增加一次阅读次数",notes = "点击一次增加一次阅读次数")
    public LogicResponse addReadCount(@RequestBody @Validated ProductReadCountDTO  productReadCountDTO) {
        productService.addReadCount(productReadCountDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/add/promotionTimes")
    @ApiOperation(value = "转发一次增加一次推广次数",notes = "转发一次增加一次推广次数")
    public LogicResponse addPromotionTimes(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        productService.addPromotionTimes(baseIdDTO);
        return LogicResponse.success("success");
    }

}
